//
//  LYTestA.m
//  Radar
//
//  Created by 吴浪 on 16/2/18.
//  Copyright © 2016年 吴浪. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "ViewController.h"
#import "AppDelegate.h"
#import "LYTouchTrace+UnitTest.h"
#import "UIImage+Extension.h"
#import "LYRadarView.h"

@interface LYTestA : XCTestCase

@end

@implementation LYTestA

- (void)setUp {
    [super setUp];
    // Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown {
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    [super tearDown];
}

- (void)testLYTouchTraceFunc_randomLessThanNum {
    LYTouchTrace *touchT = (LYTouchTrace *)[UIApplication sharedApplication];
    NSInteger num = [touchT randomLessThanNum:10];
    
    XCTAssertLessThan(num, 5, @"num < 10");
}

- (void)testB2 {
    NSLog(@"11111111");
}

- (void)testA {
    XCTAssert(1, @"not is zero");
    
}

- (void)testB1 {
    
  
    XCTAssertEqual(@"1", @"1", @"不相等");

    NSString *str1 = @"1";
    NSString *str2 = @"2";
    NSString *str3 = str1;
    NSString *str4 = @"1";
    
    XCTAssertEqualObjects(str1, str2, @"不相等");
    XCTAssertEqualObjects(str1, str3, @"不相等");
    XCTAssertEqualObjects(str2, str3, @"不相等");
    XCTAssertEqualObjects(str1, str4, @"不相等");
}

- (void)testExample {
    NSArray *a = @[@1, @2, @4];
    NSArray *b = a;
    a = @[@1];

    
    XCTAssertEqual(a, b, @"他们不同");
    XCTAssertEqualObjects(a, b, @"他们不相等");

//    XCTestExpectation *testExp = [self expectationWithDescription:@"O(∩_∩)O哈哈哈~"];
//    
//    [self waitForExpectationsWithTimeout:2.0 handler:^(NSError * _Nullable error) {
//        NSLog(@"%@", error.description);
//    }];
//    XCTAssert(NO, @"你错了");//    XCTAssertTrue();
//    XCTAssertFalse(YES, @"你错了false");
//    XCTAssertEqual(1 + 2, 2, @"1 + 2 != 2");
//  
//    NSMutableString *a = [NSMutableString string];
//    [a appendFormat:@"我"];
//    NSMutableString *b;
//    b = a;
//    [b appendFormat:@"么"];
//
//
//    id a = [NSMutableArray array];
//    [a addObject:@1];
//    id b = [NSMutableArray array];
//    [b addObject:@1];
//
//    LYRadarView *radar = [[LYRadarView alloc] init];
//    radar.targets = 10;
//    LYRadarView *a = radar;
//    radar.targets = 20;
//    LYRadarView *b = radar;

//    XCTAssertEqual(@"", @"", @"他们不同");
//    XCTAssertEqualObjects(@"", @"", @"他们不相等");
    // This is an example of a functional test case.
    // Use XCTAssert and related functions to verify your tests produce the correct results.
    
    
}

- (void)testPerformanceExampleImage1 {
    UIImage *image = [UIImage imageNamed:@"1242x2208"];
    NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
    [self measureBlock:^{
        NSData *imageData = UIImageJPEGRepresentation(image, 0.5);
    }];
}

- (void)zipImage:(UIImage *)image comptele:(void (^)(id data))comptele {
    NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
    CGFloat legth = imageData.length * 0.5;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSData *imageData = [UIImage compressImage:image toMaxLength:legth];
        if (comptele) {
            dispatch_async(dispatch_get_main_queue(), ^{
                comptele(imageData);
            });
        }
    });
}

- (void)testImageZip {
    UIImage *image = [UIImage imageNamed:@"1242x2208"];
    XCTestExpectation *expetation = [self expectationWithDescription:@"压缩失败"];
    [self zipImage:image comptele:^(NSData *data) {
        XCTAssert(data.length >= 0, @"图片压缩失败");
        [expetation fulfill];
    }];
//    [self waitForExpectationsWithTimeout:0.05 handler:^(NSError * _Nullable error) {
//        if (error) {
////            NSLog(@"%@", error.description);
//        }
//    }];
}

- (void)testPerformanceExampleImage2 {
    UIImage *image = [UIImage imageNamed:@"1242x2208"];
    NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
    NSInteger legth = imageData.length * 0.5;
//    [self measureBlock:^{
////        NSData *imageData = [UIImage compressImage:image toMaxLength:legth];
//        [self zipImage:image comptele:^(id data) {
//            
//        }];
//    }];
}

- (void)testPerformanceExample {
    // This is an example of a performance test case.
    [self measureBlock:^{
        // Put the code you want to measure the time of here.
        NSDateFormatter *mat = [[NSDateFormatter alloc] init];
        mat.dateFormat = @"y-y=y-y";
        NSLog(@"%@", [mat stringFromDate:[NSDate date]]);
    }];
}

@end
